require('../css/index.less')
let userID = JSON.parse(localStorage.getItem('users'))
if (!userID) {
	window.utils.namichref()
} else {
	var mySwiper = new Swiper('.swiper-container', {
		direction: 'horizontal', // 垂直切换选项
		loop: true, // 循环模式选项

		// 如果需要分页器
		pagination: {
			el: '.swiper-pagination',
		},
		autoplay: {
			delay: 3000,
			stopOnLastSlide: false,
			disableOnInteraction: true,
		},
	})
	let Topleft = document.querySelector('main .Topleft span')
	let TRtop = document.querySelector('main .Topright .TRtop span')
	let Bottomright = document.querySelector('main .Bottomright .shownum')
	let TRbobtn = document.querySelector('main .TRbottom button')
    let Functionaldata = document.querySelector('#Functionaldata')
    let listone = document.querySelector('#listone')
	// -----------------------------------------
	// 打卡
	window.$http.get(`/headPageInfo?userId=${userID.userId}`, function (res) {
		if (res.status !== 0) {
		} else {
			console.log(res)
			//渲染数据
			Topleft.textContent = res.data.rank
			Bottomright.textContent = res.data.insigniaNum
			TRtop.textContent = res.data.punchIn
			if (res.data.isPunch === 'true') {
				TRbobtn.setAttribute('class', 'clock-t')
				TRbobtn.textContent = '打卡成功'
			} else {
				TRbobtn.setAttribute('class', 'clock-f')
				TRbobtn.addEventListener('click', handleClock)
				TRbobtn.textContent = '今日打卡'
			}
		}
	})
	// -----------------------------------------
	//给打卡按钮绑定点击事件
	function handleClock() {
		window.$http.get(`/clockIn?userId=${userID.userId}`, function (res) {
			if (res.status === 0) {
				TRbobtn.setAttribute('class', 'clock-t')
				TRbobtn.textContent = '打卡成功'
				TRtop.textContent = Number(TRtop.textContent) + 1
				TRbobtn.removeEventListener('click', handleClock)
			}
		})
	}
    Functionaldata.addEventListener('click',function(){
        location.href = './run.html'
    })
	window.utils.showuhdy(0)
    listone.addEventListener('click',function(){
        location.href = './CourseTraining.html'
    })
}
//